﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.ZLog;

namespace UtilZ.Dotnet.Ex.Communication.Net.Ftp
{
    /// <summary>
    /// 认证/安全机制
    /// RFC 2228	Authentication/Security Mechanism
    /// </summary>
    internal class FtpAUTHCommand : FtpCommandAbs
    {
        /***********************************************************************************************************
        *
        *
        ************************************************************************************************************/


        public FtpAUTHCommand()
            : base()
        {

        }

        protected override string[] GetNames()
        {
            return new string[] { FtpCommands.AUTH };
        }

        protected override IFtpResponse PrimitiveExcute(FtpSession session, string command, string commandLine)
        {
            //Request: AUTH TLS
            //Response: 534 Local policy on server does not allow TLS secure connections.

            //Request: AUTH SSL
            //Response: 534 Local policy on server does not allow TLS secure connections.

            try
            {
                string sec = commandLine;
                if (string.IsNullOrWhiteSpace(sec))
                {
                    return new FtpCodeResponse(FtpStatusCodes.Code501, "The parameter must specify a secure connection type");
                }

                return new FtpCodeResponse(FtpStatusCodes.Code534, "Local policy on server does not allow TLS secure connections.");

                //IFtpResponse response;
                //sec = sec.ToUpper();
                //switch (sec)
                //{
                //    case "TLS":
                //        response = new FtpCodeResponse(FtpStatusCodes.Code534, "Local policy on server does not allow TLS secure connections.");
                //        break;
                //    case "SSL":
                //        response = new FtpCodeResponse(FtpStatusCodes.Code534, "Local policy on server does not allow TLS secure connections.");
                //        break;
                //    default:
                //        response = new FtpCodeResponse(FtpStatusCodes.Code534, "Local policy on server does not allow TLS secure connections.");
                //        break;
                //}

                //return response;
            }
            catch (Exception ex)
            {
                return new FtpCodeResponse(FtpStatusCodes.Code451, ex.Message);
            }
        }
    }

}
